package com.shujia.mllib

import org.wltea.analyzer.core.IKSegmenter

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object Demo8IK {
  def main(args: Array[String]): Unit = {
    val str: String = "数加学院牛逼"

    println(fit(str))
  }

  // 将分词的操作封装成一个方法
  def fit(str: String): List[String] = {

    val lb: ListBuffer[String] = ListBuffer[String]()

    val reader: StringReader = new StringReader(str)

    val segmenter: IKSegmenter = new IKSegmenter(reader, true)
    import org.wltea.analyzer.core.Lexeme
    var lex: Lexeme = segmenter.next()
    while (lex != null) {
      val word: String = lex.getLexemeText
      lb.append(word)
      lex = segmenter.next()
    }
    lb.toList
  }

}
